extern volatile long * gpbdat;
extern volatile long * gpbcon;

volatile long * SRCPND= (volatile long *) 0x4A000000;
volatile long * INTMSK= (volatile long *) 0x4A000008;
volatile long * INTPND = (volatile long *) 0x4A000010;
volatile long * INTOFFSET = (volatile long *) 0x4A000014;

volatile long * PRIORITY = (volatile long *) 0x4A00000C;
volatile long * gpfcon=(volatile long *) 0x56000050;
//volatile long * gpfdat=(volatile long * 56000054);
volatile long * gpgcon=(volatile long *) 0x56000060;
//volatile long * gpgdat=(volatile long * );
volatile long * EINTMASK = (volatile long *) 0x560000a4;
volatile long * EINTPEND = (volatile long *) 0x560000a8;

void irq_init()
{
	* gpfcon&=~((11)|(11<<4));
	* gpgcon&=~((11<<6)|(11<<22));
	* gpfcon|=(2|(2<<4));
	* gpgcon|=((2<<6)|(2<<22));
//	* SRCPND|=(1)|(1<<2)|(1<<5);
	* INTMSK&=~((1)|(1<<2)|(1<<5));
	* EINTMASK &= ~((1<<11)|(1<<19)); 
}

void do_irq()
{
	long oft = * INTOFFSET;
	volatile long val = *EINTPEND;

	*gpbdat |= (0xF<<5);

	switch(oft)
	{
		case 0:
		{
			*gpbdat |= (0xF<<5);
			*gpbdat &= ~(1<<5);
			break;
		}
		case 2:
		{
			*gpbdat |= (0xF<<5);
			*gpbdat &= ~(1<<6);
			break;
		}
		case 5:
		{
			*gpbdat |= (0xF<<5);
			if(val & (1<<11))
			{
				*gpbdat &= ~(1<<7);
				break;
			}
			if(val & (1<<19))
			{
				*gpbdat &= ~(1<<8);
				break;
			}
		default:
			break;
		}		
	}
	if(oft==5)
	{
		*EINTPEND |= (1<<11)|(1<<19); 
	}
	*SRCPND = 1<<oft;   
	*INTPND = 1<<oft;
}


